package com.kotlin.baselib.widgets

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import com.kotlin.baselib.R
import kotlinx.android.synthetic.main.layout_header_bar.view.*


class HeaderBar @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    var isShowBack = true
    var titleCenter: String? = null;
    var titleRight: String? = null;

    init {
        val style = context.obtainStyledAttributes(attrs,R.styleable.HeaderBar)
        isShowBack = style.getBoolean(R.styleable.HeaderBar_isShowBack, true)
        titleCenter = style.getString(R.styleable.HeaderBar_titleTextCenter)
        titleRight = style.getString(R.styleable.HeaderBar_titleTextRight)
        initViews()
        style.recycle()
    }

    private fun initViews() {
        View.inflate(context, R.layout.layout_header_bar, this)
        ivTitleLeft.visibility = if (isShowBack) View.VISIBLE else View.GONE
        titleCenter?.let { tvTitleCenter.text =it }
        titleRight?.let {
            tvTitleRight.text = it
            tvTitleRight.visibility = View.VISIBLE
        }
        ivTitleLeft.setOnClickListener {
            val a =it;

        }

    }

}